package com.njtcedu.microblog.common.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "login_log", schema = "microblog")
public class LoginLog implements Serializable{

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Integer id;

	@Column(name = "login_date", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date logindate;

	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "user_id", nullable = false)
	private User user;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getLogindate() {
		return logindate;
	}

	public void setLogindate(Date logindate) {
		this.logindate = logindate;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null || getClass() != obj.getClass())
			return false;
		LoginLog loginLog = (LoginLog) obj;
		return id != null ? id.equals(loginLog) : loginLog.id == null;
	}

	@Override
	public String toString() {
		return "LoginLog [id=" + id + ", logindate=" + logindate + ", user="
				+ user + "]";
	}

}
